Option Strict On
Option Explicit On

'Copyright (c) 2007-2010, William Severance, Jr., WESNet Designs
'All rights reserved.

'Redistribution and use in source and binary forms, with or without modification, are permitted
'provided that the following conditions are met:

'Redistributions of source code must retain the above copyright notice, this list of conditions
'and the following disclaimer.

'Redistributions in binary form must reproduce the above copyright notice, this list of conditions
'and the following disclaimer in the documentation and/or other materials provided with the distribution.

'Neither the name of William Severance, Jr. or WESNet Designs may be used to endorse or promote
'products derived from this software without specific prior written permission.

'Disclaimer: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
'            OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
'            AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE
'            FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
'            LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
'            INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
'            OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
'            IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'Although I will try to answer questions regarding the installation and use of this software when
'such questions are submitted via e-mail to the below address, no promise of further
'support or enhancement is made nor should be assumed.

'Developer Contact Information:
'     William Severance, Jr.
'     WESNet Designs
'     679 Upper Ridge Road
'     Bridgton, ME 04009
'     Phone: 207-647-9375
'     E-Mail: bill@wesnetdesigns.com
'     Website: www.wesnetdesigns.com
'
Imports DotNetNuke
Imports DotNetNuke.UI.Utilities.DNNClientAPI
Imports DotNetNuke.Security
Imports DotNetNuke.Services.Exceptions

Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection

Namespace WESNet.DNN.Modules.EPrayer
    Partial Class EPrayer
        Inherits WESNet.DNN.Modules.EPrayer.EPrayerModuleBase
        Implements Entities.Modules.IActionable

#Region "Private Members"

        Private _Filter As String = Nothing
        Private _RequestType As Integer = -1
        Private _Category As Integer = 0
        Private _DateRange As Integer = 1
        Private _Status As Integer = 0
        Private _Distribution As Integer = 1
        Private _OrderBy As String = "Order_Date_DESC"
        Private _AuthorID As Integer = -1
        Private _DNNPrintMode As Boolean
        Private _LastCategory As String = String.Empty
        Private _RequestAdminViewableOnly As Boolean

        Private Const minIcon As String = "images/minus.gif"
        Private Const maxIcon As String = "images/plus.gif"

        Private _pnlUpdatePanel1 As System.Web.UI.UpdatePanel
#End Region

#Region "Public Properties"

        Public Property DNNPrintMode() As Boolean
            Get
                Return _DNNPrintMode
            End Get
            Set(ByVal value As Boolean)
                _DNNPrintMode = value
            End Set
        End Property

        Public Overrides Property PageSize() As Integer
            Get
                If trPager.Visible Then
                    Return Convert.ToInt32(ddlPageSize.SelectedValue)
                Else
                    Return MyBase.PageSize
                End If
            End Get
            Set(ByVal value As Integer)
                If trPager.Visible Then
                    Dim li As ListItem
                    li = ddlPageSize.Items.FindByValue(value.ToString)
                    If Not li Is Nothing Then
                        ddlPageSize.SelectedIndex = ddlPageSize.Items.IndexOf(li)
                        MyBase.PageSize = value
                    End If
                Else
                    MyBase.PageSize = value
                End If
            End Set
        End Property

        Public Property RequestType() As Integer
            Get
                If rblRequestType.SelectedIndex <> -1 Then
                    Return Convert.ToInt32(rblRequestType.SelectedValue)
                Else
                    Return _RequestType
                End If
            End Get
            Set(ByVal value As Integer)
                Dim li As ListItem = rblRequestType.Items.FindByValue(value.ToString)
                If Not li Is Nothing Then
                    rblRequestType.SelectedIndex = rblRequestType.Items.IndexOf(li)
                    _RequestType = value
                End If
            End Set
        End Property

        Public Property Category() As Integer
            Get
                If ddlCategory.SelectedIndex <> -1 Then
                    Return Convert.ToInt32(ddlCategory.SelectedValue)
                Else
                    Return _Category
                End If
            End Get
            Set(ByVal value As Integer)
                Dim li As ListItem = ddlCategory.Items.FindByValue(value.ToString)
                If Not li Is Nothing Then
                    ddlCategory.SelectedIndex = ddlCategory.Items.IndexOf(li)
                    _Category = value
                End If
            End Set
        End Property

        Public Property DateRange() As Integer
            Get
                If ddlDateRange.SelectedIndex <> -1 Then
                    Return Convert.ToInt32(ddlDateRange.SelectedValue)
                Else
                    Return _DateRange
                End If
            End Get
            Set(ByVal value As Integer)
                Dim li As ListItem = ddlDateRange.Items.FindByValue(value.ToString)
                If Not li Is Nothing Then
                    ddlDateRange.SelectedIndex = ddlDateRange.Items.IndexOf(li)
                    _DateRange = value
                End If
            End Set
        End Property

        Public Property Status() As Integer
            Get
                If ddlStatus.SelectedIndex <> -1 Then
                    Return Convert.ToInt32(ddlStatus.SelectedValue)
                Else
                    Return _Status
                End If
            End Get
            Set(ByVal value As Integer)
                Dim li As ListItem = ddlStatus.Items.FindByValue(value.ToString)
                If Not li Is Nothing Then
                    ddlStatus.SelectedIndex = ddlStatus.Items.IndexOf(li)
                    _Status = value
                End If
            End Set
        End Property

        Public Property Distribution() As Integer
            Get
                If trDistributionFilter.Visible Then
                    Return Utilities.DistributionCBLGet(cblDistribution, False)
                Else
                    Return _Distribution
                End If
            End Get
            Set(ByVal value As Integer)
                _Distribution = value
                If trDistributionFilter.Visible Then
                    Utilities.DistributionCBLSet(cblDistribution, value)
                End If
            End Set
        End Property

        Public Property OrderBy() As String
            Get
                If ddlOrderBy.SelectedIndex <> -1 Then
                    Return ddlOrderBy.SelectedValue
                Else
                    Return _OrderBy
                End If
            End Get
            Set(ByVal value As String)
                Dim li As ListItem = ddlOrderBy.Items.FindByValue(value)
                If Not li Is Nothing Then
                    ddlOrderBy.SelectedIndex = ddlOrderBy.Items.IndexOf(li)
                    _OrderBy = value
                End If
            End Set
        End Property

        Public Property SubjectLike() As String
            Get
                Return tbSubjectLike.Text
            End Get
            Set(ByVal value As String)
                tbSubjectLike.Text = value
            End Set
        End Property

        Public Property AuthorID() As Integer
            Get
                Return _AuthorID
            End Get
            Set(ByVal value As Integer)
                _AuthorID = value
            End Set
        End Property

        Public ReadOnly Property Filter() As String
            Get
                Dim sb As New StringBuilder

                Select Case RequestType
                    Case -1
                        'all request types
                    Case 0
                        sb.Append("(IsPraise = 0)")
                    Case 1
                        sb.Append("(IsPraise <> 0)")
                End Select

                If Category > 0 Then
                    If sb.Length > 0 Then sb.Append(" AND ")
                    sb.AppendFormat("(R.CategoryID = {0})", Category)
                End If

                If DateRange < 1 Then
                    If sb.Length > 0 Then sb.Append(" AND ")
                    sb.AppendFormat("(LastPostDate >= convert(char(23), '{0:d}',126))", Now().AddDays(DateRange))
                End If

                If Status > 0 Then
                    If sb.Length > 0 Then sb.Append(" AND ")
                    sb.AppendFormat("(R.StatusID = {0})", Status)
                End If

                If RequestID > 0 Then
                    If sb.Length > 0 Then sb.Append(" AND ")
                    sb.AppendFormat("(R.RequestID = {0})", RequestID)
                End If

                If AuthorID > 0 Then
                    If sb.Length > 0 Then sb.Append(" AND ")
                    sb.AppendFormat("(P.CreatedByUserID = {0})", AuthorID)
                End If

                If SubjectLike <> String.Empty Then
                    Dim ps As New PortalSecurity
                    Dim s As String = ps.InputFilter(SubjectLike, PortalSecurity.FilterFlag.NoMarkup Or PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoSQL)
                    If sb.Length > 0 Then sb.Append(" AND ")
                    sb.AppendFormat("(R.Subject LIKE '%{0}%')", s)
                End If

                Return sb.ToString
            End Get
        End Property
#End Region

#Region "Event Handlers"

        Protected Sub Page_Init1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            If DotNetNuke.Framework.AJAX.IsInstalled Then
                DotNetNuke.Framework.AJAX.RegisterScriptManager()
                _pnlUpdatePanel1 = CType(DotNetNuke.Framework.AJAX.WrapUpdatePanelControl(lstRequests, True), System.Web.UI.UpdatePanel)
            End If
        End Sub

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                trReturn.Visible = Not String.IsNullOrEmpty(Request.QueryString("returnurl"))

                If Not String.IsNullOrEmpty(Request.QueryString("requestid")) Then
                    RequestID = Convert.ToInt32(Request.QueryString("requestid"))
                Else
                    RequestID = Null.NullInteger
                End If

                If Not String.IsNullOrEmpty(Request.QueryString("postid")) Then
                    PostID = Convert.ToInt32(Request.QueryString("postid"))
                Else
                    PostID = Null.NullInteger
                End If

                If Not String.IsNullOrEmpty(Request.QueryString("authorid")) Then
                    AuthorID = Convert.ToInt32(Request.QueryString("authorid"))
                Else
                    AuthorID = Null.NullInteger
                End If

                If Not String.IsNullOrEmpty(Request.QueryString("dnnprintmode")) Then
                    DNNPrintMode = Boolean.Parse(Request.QueryString("dnnprintmode"))
                End If

                If Not String.IsNullOrEmpty(Request.QueryString("currentpage")) Then
                    CurrentPage = Convert.ToInt32(Request.QueryString("currentpage"))
                Else
                    CurrentPage = 1
                End If

                Dim RequestedPageSize As Integer
                If Not String.IsNullOrEmpty(Request.QueryString("pagesize")) Then
                    RequestedPageSize = Convert.ToInt32(Request.QueryString("pagesize"))
                Else
                    RequestedPageSize = UserInfo.PageSize
                End If

                If Not Page.IsPostBack Then
                    PopulatePageSizes(ddlPageSize, RequestedPageSize)
                    PageSize = RequestedPageSize
                Else
                    If PageSize = -1 Then PageSize = RequestedPageSize
                End If

                ctlPager.PageSize = RequestedPageSize
                ctlPager.CurrentPage = CurrentPage
                ctlPager.TabID = TabId

                cmdClearSubjectLike.OnClientClick = "javascript:document.getElementById('" & tbSubjectLike.ClientID & "').value='';return false;"

                If Not IsPostBack Then

                    Dim epc As New EPrayerController

                    If Not IsAnonymous AndAlso MyConfiguration.TrackVisits Then
                        Dim VisitTrackingCookie As HttpCookie = Request.Cookies(Consts.VisitTrackingCookieName)
                        If VisitTrackingCookie Is Nothing OrElse VisitTrackingCookie.Value <> UserId.ToString Then
                            epc.IncrementUserVisits(ModuleId, UserId)
                            VisitTrackingCookie = New HttpCookie(Consts.VisitTrackingCookieName, UserId.ToString)
                            VisitTrackingCookie.Expires = Now.AddSeconds(Consts.VisitTrackingCookieDuration)
                            Response.Cookies.Add(VisitTrackingCookie)
                        End If
                    End If

                    If RequestID <> Null.NullInteger Then
                        lstRequests.SelectedIndex = 0
                        tblFilterRequests.Visible = False
                    Else
                        If PostID <> Null.NullInteger Then
                            Try
                                RequestID = epc.GetPost(PostID).RequestID
                                lstRequests.SelectedIndex = 0
                                tblFilterRequests.Visible = False
                            Catch
                                tblFilterRequests.Visible = True
                                RequestID = Null.NullInteger
                            End Try
                        End If
                    End If

                    lnkAddRequest.NavigateUrl = EditUrl("RequestID", "-1")
                    lnkAddRequest.Visible = CanPost()
                    lnkAddRequest1.NavigateUrl = lnkAddRequest.NavigateUrl
                    lnkAddRequest1.Visible = lnkAddRequest.Visible

                    lnkModerate.Visible = CanModerate() AndAlso MyConfiguration.PostsToModerate > 0
                    lnkModerate.Text = Localize("lnkModerate") & " (" & MyConfiguration.PostsToModerate.ToString & ")"
                    lnkModerate.NavigateUrl = EditUrl("mod")
                    lnkModerate1.Visible = lnkModerate.Visible
                    lnkModerate1.Text = lnkModerate.Text
                    lnkModerate1.NavigateUrl = lnkModerate.NavigateUrl

                    trTrackAll.DataBind()

                    cbIsTrackingAll.Checked = UserInfo.IsTrackingAllPosts

                    ddlCategory.DataSource = epc.GetCategories(ModuleId)
                    ddlCategory.DataBind()
                    ddlCategory.Items.Insert(0, New ListItem(Localize("All_Categories"), "0"))

                    ddlStatus.DataSource = epc.GetStati()
                    ddlStatus.DataBind()
                    ddlStatus.Items.Insert(0, New ListItem(Localize("All_Stati"), "0"))

                    BindDistributions()

                    If Not String.IsNullOrEmpty(Request.QueryString("type")) Then RequestType = Convert.ToInt32(Request.QueryString("type"))
                    If Not String.IsNullOrEmpty(Request.QueryString("category")) Then Category = Convert.ToInt32(Request.QueryString("category"))
                    If Not String.IsNullOrEmpty(Request.QueryString("daterange")) Then DateRange = Convert.ToInt32(Request.QueryString("daterange"))
                    If Not String.IsNullOrEmpty(Request.QueryString("status")) Then Status = Convert.ToInt32(Request.QueryString("status"))
                    If Not String.IsNullOrEmpty(Request.QueryString("distribution")) Then
                        Distribution = Convert.ToInt32(Request.QueryString("distribution")) And UserInfo.ViewableDistributions
                    Else
                        Distribution = UserInfo.ViewableDistributions
                    End If

                    If Not String.IsNullOrEmpty(Request.QueryString("orderby")) Then
                        OrderBy = Request.QueryString("orderby")
                    Else
                        OrderBy = UserInfo.OrderBy
                    End If

                    If Not String.IsNullOrEmpty(Request.QueryString("subject")) Then
                        Dim s As String = Server.UrlDecode(Request.QueryString("subject"))
                        Dim ps As New PortalSecurity
                        SubjectLike = ps.InputFilter(s, PortalSecurity.FilterFlag.NoMarkup Or PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoSQL)
                    End If

                    lnkPrint.NavigateUrl = PrintURL()

                    GetRequests()
                End If
            Catch exc As Exception        'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
            If IsAnonymous Then
                EnableMinMax(btnFilterRequests, tblFilterRequests, True, Page.ResolveUrl(minIcon), Page.ResolveUrl(maxIcon), MinMaxPersistanceType.Page)
            Else
                EnableMinMax(btnFilterRequests, tblFilterRequests, True, Page.ResolveUrl(minIcon), Page.ResolveUrl(maxIcon), MinMaxPersistanceType.Personalization)
            End If
        End Sub

        Protected Sub lstRequests_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles lstRequests.ItemDataBound
            If (e.Item.ItemType = ListItemType.Item _
                 Or e.Item.ItemType = ListItemType.AlternatingItem _
                   Or e.Item.ItemType = ListItemType.SelectedItem) Then
                Dim objRequest As RequestInfo = CType(e.Item.DataItem, RequestInfo)
                If objRequest.IsExpired AndAlso CanModerate Then
                    e.Item.CssClass = "EPrayer_AdminRequestItemTemplate"
                    _RequestAdminViewableOnly = True
                End If
                If OrderBy = "Order_Category" Then
                    Dim Category As String = objRequest.Category
                    If Category <> _LastCategory Then
                        e.Item.FindControl("CategoryHeader").Visible = True
                        _LastCategory = Category
                    Else
                        e.Item.FindControl("CategoryHeader").Visible = False
                    End If
                End If
            End If

            If e.Item.ItemType = ListItemType.SelectedItem Then
                Dim epc As New EPrayerController
                Dim _RequestID As Integer = Convert.ToInt32(lstRequests.DataKeys(lstRequests.SelectedIndex))
                Dim lstPosts As DataList = CType(e.Item.FindControl("lstPosts"), DataList)
                If Not lstPosts Is Nothing Then
                    Dim objPosts As List(Of PostInfo) = epc.GetPosts(_RequestID, Distribution, True)
                    lstPosts.DataSource = objPosts
                    lstPosts.DataBind()
                End If

                Dim cbIsTracking As CheckBox = CType(e.Item.FindControl("cbIsTracking"), CheckBox)
                If Not cbIsTracking Is Nothing Then
                    cbIsTracking.Checked = CType(e.Item.DataItem, RequestInfo).IsTracking
                End If

                If MyConfiguration.TrackViews Then
                    epc.IncrementRequestViews(_RequestID)
                End If
            End If
        End Sub

        Protected Sub lstRequests_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles lstRequests.ItemCommand
            Select Case e.CommandName
                Case "Select"
                    lstRequests.SelectedIndex = e.Item.ItemIndex
                Case "UnSelect"
                    lstRequests.SelectedIndex = -1
                    If PostID <> -1 Then
                        Response.Redirect(ReturnUrl(), True)
                    End If
            End Select
            GetRequests() ' In either case, re-bind the requests datalist
        End Sub

        Protected Sub cbIsTracking_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            If lstRequests.SelectedIndex <> -1 Then
                RequestID = CType(lstRequests.DataKeys(lstRequests.SelectedIndex), Integer)
                If Not sender Is Nothing AndAlso TypeOf (sender) Is CheckBox Then
                    Dim cbIsTracking As CheckBox = CType(sender, CheckBox)
                    Dim epc As New EPrayerController
                    epc.StartEndRequestTracking(RequestID, UserId, cbIsTracking.Checked)
                End If
            End If
        End Sub

        Protected Sub cbIsTrackingAll_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbIsTrackingAll.CheckedChanged
            Dim epc As New EPrayerController
            epc.StartEndTrackingAllPosts(ModuleId, UserId, cbIsTrackingAll.Checked)
        End Sub

        Protected Sub btnGetRequests_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetRequests.Click
            CurrentPage = 1 'reset to first page when filter is applied
            Response.Redirect(NavigateURL(TabId, "", GetNavigationParams()), True)
        End Sub

        Protected Sub ddlPageSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPageSize.SelectedIndexChanged
            CurrentPage = 1 'reset to first page when filter is applied
            Response.Redirect(NavigateURL(TabId, "", GetNavigationParams()), True)
        End Sub

        Protected Sub cmdReturn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdReturn.Click
            Response.Redirect(ReturnUrl, True)
        End Sub



#End Region

#Region "Private and Protected Methods"

        Private Sub BindDistributions()
            If UserInfo.ViewableDistributions = 1 Then
                trDistributionFilter.Visible = False
            Else
                Dim epc As New EPrayerController
                cblDistribution.DataSource = epc.GetDistributions(ModuleId)
                cblDistribution.DataBind()
                Utilities.DistributionCBLEnableViewable(cblDistribution, UserInfo.ViewableDistributions)
            End If
        End Sub

        Protected Sub GetRequests()
            Dim TotalRecords As Integer
            Dim objEPrayers As New EPrayerController
            Dim objRequests As List(Of RequestInfo)

            If DNNPrintMode Then
                PageSize = 0
                Me.tblFilterRequests.Visible = False
            End If

            Dim IncludeExpired As Boolean = CanModerate

            objRequests = objEPrayers.GetRequests(ModuleId, Distribution, Filter, IncludeExpired, OrderBy, UserId, PageSize, CurrentPage - 1, TotalRecords)
            If objRequests.Count > 0 Then
                _RequestAdminViewableOnly = False
                lstRequests.Visible = True
                lstRequests.DataSource = objRequests
                lstRequests.DataBind()
                With ctlPager
                    .TotalRecords = TotalRecords
                    .QuerystringParams = GetQueryStringParams()
                End With
                lnkPrint.Visible = True
                lnkAddRequest1.Visible = lnkAddRequest.Visible
                trPager.Visible = True
                ctlPager.Visible = PageSize <> 0 And TotalRecords > PageSize
                trError.Visible = False
                If lstRequests.SelectedIndex = -1 Then
                    lblInstructions.Text = Localize("ExpandInstructions")
                Else
                    lblInstructions.Text = Localize("CollapseInstructions")
                End If
                If _RequestAdminViewableOnly Then
                    lblInstructions.Text = lblInstructions.Text & " " & Localize("AdminViewableOnly")
                End If
            Else
                lstRequests.Visible = False
                lnkPrint.Visible = False
                lblInstructions.Text = String.Empty
                lnkAddRequest1.Visible = False
                trPager.Visible = False
                trError.Visible = True
                lblError.Text = Localize("No_Requests_Found")
            End If
        End Sub

        Protected Function GetNavigationParams() As String()
            Return GetNavigationParams(False)
        End Function

        Protected Function GetNavigationParams(ByVal Print As Boolean) As String()
            Dim params As New ArrayList
            Dim result As String()
            If RequestID <> -1 Then params.Add("requestid=" & RequestID.ToString)
            If PostID <> -1 Then params.Add("postid=" & PostID.ToString)
            If AuthorID <> -1 Then params.Add("authorid=" & AuthorID.ToString)
            If PageSize <> UserInfo.PageSize Then params.Add("pagesize=" & PageSize.ToString)
            If CurrentPage <> 1 Then params.Add("currentpage=" & CurrentPage.ToString)
            If RequestType <> -1 Then params.Add("type=" & RequestType.ToString)
            If Category > 0 Then params.Add("category=" & Category.ToString)
            If DateRange < 1 Then params.Add("daterange=" & DateRange.ToString)
            If Status > 0 Then params.Add("status=" & Status.ToString)
            If Not Utilities.IsDistributionCBLAllChecked(cblDistribution) Then params.Add("distribution=" & Distribution.ToString)
            If OrderBy <> UserInfo.OrderBy Then params.Add("orderby=" & OrderBy)
            If SubjectLike <> String.Empty Then
                Dim ps As New PortalSecurity
                Dim s As String = ps.InputFilter(SubjectLike, PortalSecurity.FilterFlag.NoMarkup Or PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoSQL)
                params.Add("subject=" & Server.UrlEncode(s))
            End If
            If Print Then
                params.Add("mid=" & ModuleId.ToString)
                params.Add("SkinSrc=" & DotNetNuke.Common.Globals.QueryStringEncode((("[G]" & Skins.SkinController.RootSkin) & "/_default/No Skin")))
                params.Add("ContainerSrc=" & DotNetNuke.Common.Globals.QueryStringEncode((("[G]" & Skins.SkinController.RootContainer) & "/_default/No Container")))
                params.Add("returnurl=" & Request.RawUrl)
            End If
            result = CType(params.ToArray(GetType(String)), String())
            Return result
        End Function

        Protected Function GetQueryStringParams() As String
            Dim sb As New StringBuilder
            Dim params As String() = GetNavigationParams()
            For Each s As String In params
                If Not s.StartsWith("currentpage") Then 'And Not s.StartsWith("pagesize")
                    sb.Append("&")
                    sb.Append(s)
                End If
            Next
            Return sb.ToString
        End Function

        Protected Function PrintURL() As String
            Return NavigateURL(Me.TabId, "print", GetNavigationParams(True))
        End Function

#End Region

#Region "Optional Interfaces"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Registers the module actions required for interfacing with the portal framework
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
            Get
                Dim Actions As New Entities.Modules.Actions.ModuleActionCollection
                Actions.Add(GetNextActionID, Localization.GetString("Add_New_Request", LocalResourceFile), "", "", ControlPath & "images/icon_prayer_16px.gif", EditUrl("RequestID", "-1"), False, Security.SecurityAccessLevel.View, CanPost(), False)
                Actions.Add(GetNextActionID, Localization.GetString("Preferences", LocalResourceFile), "", "", "settings.gif", EditUrl("UserID", UserId.ToString, "prefs"), False, SecurityAccessLevel.View, Not IsAnonymous, False)
                Actions.Add(GetNextActionID, Localization.GetString("MyPosts", LocalResourceFile), "", "", "icon_profile_16px.gif", EditUrl("UserID", UserId.ToString, "myposts"), False, SecurityAccessLevel.View, Not IsAnonymous, False)
                Actions.Add(GetNextActionID, Localization.GetString("Moderate", LocalResourceFile), "", "", "icon_authentication_16px.gif", EditUrl("mod"), False, SecurityAccessLevel.View, MyConfiguration.EnableModeration AndAlso CanModerate(), False)
                Actions.Add(GetNextActionID, Localization.GetString("Manage_Moderators", LocalResourceFile), "", "", "icon_users_16px.gif", EditUrl("mngmods"), False, SecurityAccessLevel.Admin, True, False)
                Actions.Add(GetNextActionID, Localization.GetString("Manage_Users", LocalResourceFile), "", "", "icon_users_16px.gif", EditUrl("mngusers"), False, SecurityAccessLevel.View, IsAdministrator OrElse (MyConfiguration.EnableModeration AndAlso CanModerate), False)
                Actions.Add(GetNextActionID, Localization.GetString("Manage_Expired_Posts", LocalResourceFile), "", "", "action_delete.gif", EditUrl("mngexp"), False, SecurityAccessLevel.Admin, True, False)
                Return Actions
            End Get
        End Property

#End Region

    End Class

End Namespace
